package com.example.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.example.springboot.domain.Resource;
import com.example.springboot.domain.ResourseVo;
import com.example.springboot.domain.ResponseResult;
import com.example.springboot.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    public ResourceService resourceService;

//    @RequestMapping("/findAllResource")
//    public ResponseResult findAllResourceByPage(ResourseVo resourseVo){
//        PageInfo<Resource> pageInfo = resourceService.findAllResourceByPage(resourseVo);
//
//
//        return  new ResponseResult(true,200,"资源信息分页多条件查询成功",pageInfo);
//
//    }

    @RequestMapping("/findAllResource")
    public ResponseResult findAllResourceByPage(@RequestBody ResourseVo resourseVo){
        PageInfo<Resource> pageInfo = resourceService.findAllResourceByPage(resourseVo);
        return  new ResponseResult(true,200,"资源信息分页多条件查询成功",pageInfo);
    }

    @RequestMapping("/addOrUpdateResource")
    public  ResponseResult addOrUpdateResource(@RequestBody Resource resource) {
        if(resource.getId()==null) {
            resourceService.addResource(resource);
            return new ResponseResult(true,200,"添加资源信息成功",null);
        } else {
            resourceService.updateResource(resource);
            return new ResponseResult(true,200,"修改资源信息成功",null);
        }
    }

    @RequestMapping("deleteResource")
    public ResponseResult deleteResource(@RequestParam Integer id) {
        resourceService.deleteResource(id);
        return new ResponseResult(true,200,"删除成功",null);
    }

}
